/*
 * @Date: 2024-11-28 10:35:07
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2025-02-17 14:48:27
 * @Description: 
 */
import PojoUtils from '../utils/PojoUtils'

export class DbSourceType {
  constructor (value, label, order, config, visible=true) {
    this.value = value
    this.label = label
    this.order = order
    this.config = config
    this.visible = visible
  }

  static get SQL () {
    return new DbSourceType('sql', 'SQL', 4, {
      content: '',
      isParams:false, // 参数是否点击
      paramColumns:[], // 参数列
      responseFunc: '',
    })
  }
  static get VIEW () {
    return new DbSourceType('view', '视图', 2, {
      dataType: 'view',
      dataCode: '',
      dataParams: '',
      responseFunc: '',
    }, false)
  }
  static get STATIC () {
    return new DbSourceType('static', '静态', 1, {
      dataValue: ''
    })
  }
  static get SERVER () {
    return new DbSourceType('server', '接口', 3, {
      // 接口地址
      url: '',
      // 请求类型
      method: 'POST',
      // 请求参数
      params: '',
      // 参数类型
      paramsType: 'data',
      // 数据处理
      responseFunc: ''
    })
  }

  static getTypes () {
    const types = PojoUtils.getOwnPropertyStatics(this, true)
    return types.filter(i => i.visible).sort((a, b) => a.order - b.order)
  }

  /**
   * 比对是否相同
   * 
   * @param {Object|String} item 需要比对的数据
   * @returns {Boolean} true-相同 false-不相同
   */
  equals (item) {
    if (item instanceof DbSourceType) {
      return item.value === this.value
    } else {
      return item === this.value
    }
  }
}


